//
//  TeamStatisticsCell.m
//  TrainTree
//
//  Created by wanghui on 2017/9/19.
//  Copyright © 2017年 YouYeShu. All rights reserved.
//

#import "TeamStatisticsCell.h"
#import "DVLineChartView.h"
#import "UIView+Extension.h"
#import "UIColor+Hex.h"
@interface TeamStatisticsCell ()<DVLineChartViewDelegate>

@end
@implementation TeamStatisticsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self clips:self.studyPoint];
    [self clips:self.coursePoint];
    [self clips:self.commitPoint];
}

- (void)configWithArray:(NSArray *)array
{
    NSMutableArray *feedArray = [NSMutableArray array];
    NSMutableArray *lessonArray = [NSMutableArray array];
//    NSMutableArray *positionArray = [NSMutableArray array]; 预留
    NSMutableArray *studyTimeArray = [NSMutableArray array];
    NSMutableArray *userNameArray = [NSMutableArray array];

    for (NSDictionary *dic in array) {
        [feedArray addObject:dic[@"feedbackCount"]];
        [lessonArray addObject:dic[@"lessonCount"]];
//        [positionArray addObject:dic[@"position"]];
        [studyTimeArray addObject:dic[@"studyTimeCount"]];
        [userNameArray addObject:dic[@"userName"]];
    }
    [self setChartUIWithNameArray:userNameArray lessonArray:lessonArray feedArray:feedArray studyArray:studyTimeArray];

}

- (void)setChartUIWithNameArray:(NSArray *)nameArray lessonArray:(NSArray *)lessonArray feedArray:(NSArray *)feedArray studyArray:(NSArray *)studyArray
{
    DVLineChartView *ccc = [[DVLineChartView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 170)];
    [self.chartView addSubview:ccc];

    ccc.yAxisViewWidth = 0;
    ccc.numberOfYAxisElements = 4;
    ccc.delegate = self;
        ////    ccc.pointUserInteractionEnabled = YES;
    ccc.yAxisMaxValue = 24;
    ccc.pointGap =  (ScreenWidth - 56) / 5;
    ccc.showSeparate = YES;
    ccc.separateColor = rgb(231.0f, 231.0f, 231.0f);
    ccc.textColor = rgb(74.0f, 74.0f, 74.0f);
    ccc.backColor = [UIColor clearColor];
        // 坐标轴颜色
    ccc.axisColor = rgb(231.0f, 231.0f, 231.0f);
    ccc.xAxisTitleArray = nameArray;

    ccc.x = 0;
    ccc.y = 0;
    ccc.width = ScreenWidth;
    ccc.height = 170;

    DVPlot *plotTime = [[DVPlot alloc] init];
    plotTime.pointArray = studyArray;
    plotTime.lineColor = rgba(44.0f, 126.0f, 194.0f,0.3);
    plotTime.pointColor = rgba(44.0f, 126.0f, 194.0f,0.3);
    plotTime.chartViewFill = YES;
    plotTime.withPoint = NO;

    DVPlot *plotCourse = [[DVPlot alloc] init];
    plotCourse.pointArray = lessonArray;
    plotCourse.lineColor = rgb(51.0f,181.0f,158.0f);
    plotCourse.pointColor = rgb(51.0f,181.0f,158.0f);
    plotCourse.chartViewFill = NO;
    plotCourse.withPoint = YES;

//    DVPlot *plotCommit = [[DVPlot alloc] init];
//    plotCommit.pointArray = feedArray;
//    plotCommit.lineColor = rgb(235.0f,107.0f,52.0f);
//    plotCommit.pointColor = rgb(235.0f,107.0f,52.0f);
//    plotCommit.chartViewFill = NO;
//    plotCommit.withPoint = YES;

    [ccc addPlot:plotTime];
    [ccc addPlot:plotCourse];
//    [ccc addPlot:plotCommit];
    [ccc draw];
}
- (void)lineChartView:(DVLineChartView *)lineChartView DidClickPointAtIndex:(NSInteger)index {

    NSLog(@"%ld", index);

}

- (void)clips:(UILabel *)label
{
    label.layer.cornerRadius = 4.0f;
    label.layer.masksToBounds = YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
